﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;

namespace GUI
{
    public partial class frmDangNhap : Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        private static int _ma;

        public static int Ma
        {
            get { return _ma; }
            set { _ma = value; }
        }
        private static int _bophan;

        public static int BoPhan
        {
            get { return _bophan; }
            set { _bophan = value; }
        }
        private static String _ten;

        public static String Ten
        {
            get { return _ten; }
            set { _ten = value; }
        }

        private void btnOK_Click_1(object sender, EventArgs e)
        {
            if (txtUsername.Text == "" || txtPassword.Text == "")
            {
                MessageBox.Show("Chưa nhập tên đăng nhập hoặc mật khẩu!");
            }
            else
            {
                String TaiKhoan = txtUsername.Text;
                String MatKhau = txtPassword.Text;
                DangNhapBUS dnBUS = new DangNhapBUS();
                bool kq = dnBUS.KiemTraDangNhap(TaiKhoan, MatKhau, ref _ma, ref _bophan, ref _ten);
                if (!kq)
                {
                    MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                this.Visible = false;
                frmMain frm = new frmMain();
                frm.ShowDialog();
                
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            ActiveControl = txtUsername;
        }

        private void txtUsername_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
